home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CTOOLS10.ARJ / HASH.H < prev    next >
C/C++ Source or Header  |  1991-12-31  |  3KB  |  97 lines

  1. /****************************************************************************
  2. *
  3. *                    Copyright (C) 1991 Kendall Bennett.
  4. *                            All rights reserved.
  5. *
  6. * Filename:        $RCSfile: hash.h $
  7. * Version:        $Revision: 1.5 $
  8. *
  9. * Language:        ANSI C
  10. * Environment:    any
  11. *
  12. * Description:    Header file for hash table module.
  13. *
  14. * $Id: hash.h 1.5 91/12/31 19:41:11 kjb Exp $
  15. *
  16. * Revision History:
  17. * -----------------
  18. *
  19. * $Log:    hash.h $
  20. * Revision 1.5  91/12/31  19:41:11  kjb
  21. * Modified include files directories.
  22. * Revision 1.4  91/09/27  03:11:00  kjb
  23. * Added compatibility with C++.
  24. * Revision 1.3  91/09/26  10:07:36  kjb
  25. * Took out extern references
  26. * Revision 1.2  91/09/02  11:11:53  ROOT_DOS
  27. * Minor revision. Added function hsh_kill() to remove the hash table and all
  28. * symbols in the hash table.
  29. * Revision 1.1  91/08/16  13:19:37  ROOT_DOS
  30. * Initial revision
  31. *
  32. ****************************************************************************/
  33.  
  34. #ifndef    __HASH_H
  35. #define    __HASH_H
  36.  
  37. #ifndef    __DEBUG_H
  38. #include "debug.h"
  39. #endif
  40.  
  41. /*---------------------- Macros and type definitions ----------------------*/
  42.  
  43. typedef struct HSH_BUCKET {
  44.     struct HSH_BUCKET    *next;
  45.     struct HSH_BUCKET    **prev;
  46.     } HSH_BUCKET;
  47.  
  48. typedef struct {
  49.     int            size;        /* Max number of elements in table            */
  50.     int            numsyms;    /* Number of elements currently in table    */
  51.     unsigned    (*hash)(void *);        /* The hash function            */
  52.     int            (*cmp)(void *,void *);    /* Comparison function            */
  53.     HSH_BUCKET    *table[1];    /* First element of actual hash table        */
  54.     } HASH_TAB;
  55.  
  56. /* Return a pointer to the user space given the address of the header of
  57.  * a symbol.
  58.  */
  59.  
  60. #define    HSH_USERSPACE(h)    ((void*)((HSH_BUCKET*)(h) + 1))
  61.  
  62. /* Return a pointer to the header of a symbol, given the address of the
  63.  * user space.
  64.  */
  65.  
  66. #define    HSH_HEADER(n)        ((HSH_BUCKET*)(n) - 1)
  67.  
  68. /*-------------------------- Function Prototypes --------------------------*/
  69.  
  70. #ifdef __cplusplus
  71. extern "C" {
  72. #endif
  73.  
  74. void *hsh_newsym(int size);
  75. void hsh_freesym(void *sym);
  76. HASH_TAB *hsh_init(unsigned maxsym,unsigned (*hash_function)(),
  77.                    int (*cmp_function)() );
  78. void hsh_kill(HASH_TAB *tabp,void (*freeSym)());
  79. void *hsh_addsym(HASH_TAB *tabp, void *isym);
  80. void hsh_delsym(HASH_TAB *tabp, void *isym);
  81. void *hsh_findsym(HASH_TAB *tabp, void *sym);
  82. void *hsh_nextsym(HASH_TAB *tabp,void *i_last);
  83. int hsh_ptab(HASH_TAB *tabp,void (*print)(),void *param,int sort);
  84. unsigned hash_add(unsigned char *name);                    /* in hashadd.c */
  85. unsigned hash_pjw(unsigned char *name);                    /* in hashpjw.c */
  86.  
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90.  
  91. #endif
  92.